package com.ddwl.shop.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.shop.ShopCollectionBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.shop.ShopCollectionVo;
import com.ddwl.shop.service.ShopCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author Fu Zhaohui
 * @version 1.0.0.RELEASE
 * @date 2020/3/5 10:59 上午
 */
@Api(tags = "门店收藏服务")
@RequestMapping("ShopCollection")
@RestController
public class ShopCollectionController extends BaseController {

    @Resource
    private ShopCollectionService shopCollectionService;

    @PostMapping("/create")
    @ApiOperation("创建收藏")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo create(@Valid @RequestBody ShopCollectionBo bo) {
        bo.setUserId(getUserId());
        shopCollectionService.create(bo);
        return RestVo.ok();
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除收藏")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo delete(@RequestParam String id) {
        shopCollectionService.delete(id);
        return RestVo.ok();
    }

    @PostMapping("/page")
    @ApiOperation("分页查询店铺收藏")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<PageVo<ShopCollectionVo>> page(@Valid @RequestBody PageBo pageBo) {
        PageVo<ShopCollectionVo> shopCollectionVos=shopCollectionService.page(pageBo,getUserId());
        return RestVo.ok(shopCollectionVos);
    }
}
